#include "sCRFrame.h"
#include "sCRIFrame.h"
#include "sGUI.h"

namespace sgui
{
namespace res
{

#ifdef _EDITOR
void sComponentRectFrame::exportRTTI(rtti::sInfoList& list)
{
	sComponentRect::exportRTTI(list);
}
#endif
	
inst::sComponentRectInstance* sComponentRectFrame::getInstance(inst::sComponentInstance& instanceFor, s32 id) const
{
	return new inst::sComponentRectFrame(*this, instanceFor, id);
}
		
void sComponentRectFrame::load(const db::Record &file)
{
	sComponentRect::load(file);
    const db::Record &frames = file[L"frames"];
    
    for (int i = 0, t = frames.getSize(); i < t; ++i)
    {
        sFrameGroup *group = new sFrameGroup(getGui());
        group->load(frames[i]);
        m_frames.push_back(group);
    }
}

void sComponentRectFrame::save(db::Record &file) const
{
	sComponentRect::save(file);

    db::Record &frames = file[L"frames"];
    frames.setSize(m_frames.size());

    for (int i = 0, t = m_frames.size(); i < t; ++i)
    {
        m_frames[i]->save(frames[i]);
    }
}

void sComponentRectFrame::clear()
{
	sComponentRect::clear();
    for (int i = 0, t = m_frames.size(); i < t; ++i)
    {
        delete m_frames[i];
    }
    m_frames.clear();
}

sComponentRectFrame::sComponentRectFrame(sGUI& gui) :
	sComponentRect(gui)
{
    m_frames.push_back(new sFrameGroup(gui));
}
	
};
};